<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //1.计算两个数a和b,根据传入的fun函数,进行不同的计算
        var value = function(a, b, fn) {
            return fn(a, b);
        }
        var add = (a, b) => a + b;
        var sub = (a, b) => a - b;
        //函数调用
        console.log(value(1, 3, add));
        console.log(value(1, 3, sub));

        //2.求数组最大值
        // var mar = (arr, fn) => {
        //         var max = arr[0];
        //         for (let i = 1; i < arr.length; i++) {
        //             max = fn(max, arr[i]);
        //         }
        //         return max;
        //     }
        //     //调用
        // var maxNum = max([2, 7, 9, 5, 4], (a, b) => a > b ? a : b);
        // console.log(maxNum);

        //3.
        var ages = [32, 33, 16, 40];

        function check(age) {
            return age >= 18;
        }

        function myFunction() {
            document.getElementById("demo").innerHTML = ages.filter(check)
        }
    </script>
</head>

<body>

</body>

</html>